@echo off
echo ======================================
echo 汇川Easy521 WPF程序编译脚本
echo ======================================

REM 尝试使用 Visual Studio 2022 的 MSBuild
if exist "C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\MSBuild.exe" (
    echo 找到 Visual Studio 2022 Community MSBuild
    "C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\MSBuild.exe" Easy521WPF.csproj /p:Configuration=Release /p:Platform="Any CPU"
    goto :end
)

if exist "C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Current\Bin\MSBuild.exe" (
    echo 找到 Visual Studio 2022 Professional MSBuild
    "C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Current\Bin\MSBuild.exe" Easy521WPF.csproj /p:Configuration=Release /p:Platform="Any CPU"
    goto :end
)

REM 尝试使用 Visual Studio 2019 的 MSBuild
if exist "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe" (
    echo 找到 Visual Studio 2019 Community MSBuild
    "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe" Easy521WPF.csproj /p:Configuration=Release /p:Platform="Any CPU"
    goto :end
)

if exist "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\MSBuild.exe" (
    echo 找到 Visual Studio 2019 Professional MSBuild
    "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\MSBuild.exe" Easy521WPF.csproj /p:Configuration=Release /p:Platform="Any CPU"
    goto :end
)

REM 尝试使用 .NET Framework 4.8 的 MSBuild
if exist "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe" (
    echo 找到 .NET Framework MSBuild
    C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe Easy521WPF.csproj /p:Configuration=Release /p:Platform="Any CPU"
    goto :end
)

if exist "C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe" (
    echo 找到 .NET Framework MSBuild (32位)
    C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe Easy521WPF.csproj /p:Configuration=Release /p:Platform="Any CPU"
    goto :end
)

echo ======================================
echo 错误: 未找到 MSBuild.exe
echo 请确保已安装 Visual Studio 或 .NET Framework SDK
echo ======================================
goto :eof

:end
echo ======================================
echo 编译完成！
echo 可执行文件位于: bin\Release\Easy521WPF.exe
echo ======================================
pause
